import type { Metadata } from 'next'; import Link from 'next/link'; import { notFound } from 'next/navigation'; import { Download } from 'lucide-react'; import { PageHeader, Section, KV, Note } from '@/components/ui/section'; import { Badge, ClaimBadge, ConfidenceBadge } from '@/components/ui/badge'; import { EmptyState } from '@/components/ui/empty-state'; import { Freshness } from '@/components/ui/freshness'; import { JsonView } from '@/components/ui/json-view'; import { BarChart } from '@/components/charts/bar-chart'; import { getMetric, snapshotsForMetric, rankingRows, type Snapshot } from '@/lib/queries/rankings'; import { sourceInfoById } from '@/lib/queries/provenance'; import { fmtDate, fmtDateTime, fmtInt, fmtValue, scopeLabel, unitLabel, humanize } from '@/lib/format'; import { str, type SP } from '@/lib/search-params'; export const dynamic = 'force-dynamic'; export async function generateMetadata({ params }: { params: Promise<{ metric: string }> }): Promise { const m = await getMetric((await params).metric); return m ? { title: `${m.name} — ranking`, description: m.description } : { title: 'Ranking' }; } function Delta({ rank, prev }: { rank: number; prev: number | null }) { if (prev == null) return new; const d = prev - rank; if (d === 0) return =; return ( 0 ? 'text-ok' : 'text-danger'} title={`Previous rank ${prev}`}> {d > 0 ? '▲' : '▼'} {Math.abs(d)} ); } export default async function RankingPage({ params, searchParams }: { params: Promise<{ metric: string }>; searchParams: Promise }) { const { metric: slug } = await params; const sp = await searchParams; const metric = await getMetric(slug); if (!metric) notFound(); const snapshots = await snapshotsForMetric(slug); const wanted = str(sp, 'scope'); const snap: Snapshot | null = snapshots.find((s) => s.scope_key === wanted) ?? snapshots[0] ?? null; const rows = snap ? await rankingRows(snap.id) : []; const srcInfo = snap ? await sourceInfoById(snap.source_ids) : new Map(); const eligibility = Object.entries(metric.eligibility ?? {}); const isBurden = metric.category === 'burden' || metric.category === 'lethality' || metric.category === 'unmet_need'; return (

{metric.formula_version} unit: {unitLabel(metric.unit)} {metric.higher_is_worse == null ? 'higher is first (neutral)' : metric.higher_is_worse ? 'higher = worse' : 'higher = better'} All metrics

{snapshots.length === 0 ? ( {isBurden ? 'This metric depends on epidemiology observations. Global burden data (IARC / GLOBOCAN) is awaiting license review and SEER awaits credentials; no snapshot is produced until licensed observations exist for at least one scope with ten or more top-level cancers.' : 'This metric depends on counters that are refreshed after the relevant connector runs (ClinicalTrials.gov, PubMed, CIViC, GDC). No snapshot exists yet on this environment.'}
Formula {metric.formula}
) : (
{snap && rows.length ? ( <> ({ label: r.canonical_name, value: r.value, muted: r.confidence === 'LOW' || r.confidence === 'INSUFFICIENT_DATA' }))} />
{rows.map((r) => ( ))}
Rank Δ Cancer {metric.name} ({unitLabel(metric.unit)}) Percentile Confidence Sources Why #n?
{r.rank} {r.canonical_name} {fmtValue(r.value, r.unit)} {r.percentile} {snap.source_ids.map((id) => { const s = srcInfo.get(id); return ( {s?.slug ?? id} ); })}
inputs

ranking row {r.id}

) : ( This snapshot has no rows. )}
)}
); }